package com.heatup.apt.common.dao;

import com.baomidou.mybatisplus.mapper.AutoMapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.heatup.apt.model.api.course.CourseCoachDetailResultModel;
import com.heatup.apt.model.course.CoursePrivteFeeVO;
import com.heatup.apt.model.course.CourseSign;
import com.heatup.apt.model.course.CourseSignDetailModel;
import com.heatup.apt.model.course.UserCourseSignDetailModel;
import com.heatup.apt.model.order.OrderInfo;
import com.heatup.apt.model.order.OrderPrivateUser;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.List;
import java.util.Map;


/**
 *
 * CourseSign 表数据库控制层接口
 *
 */
@Component
public interface CourseSignMapper extends AutoMapper<CourseSign> {

    /**
     * 根据用户id 课程id查询用户课程信息
     */
    List<Map<String, Object>> queryUserCourseInfo(@Param("user_id") Integer userId, @Param("course_id") Integer courseId, @Param("isclose") Integer isclose, @Param("order_id") Integer  orderId);


    /**
     * 销课
     *
     * @param storeId   门店地址
     * @param closeTime 销课时间
     * @return
     */
    @Update({
            "UPDATE course_sign SET store_id=#{store_id}, close_time=#{close_time}, start_time=#{start_time}, isclose=1 where id=#{id}"
    })
    Integer closeCourse(@Param("id") Integer id, @Param("store_id") Integer storeId, @Param("close_time") Date closeTime, @Param("start_time") Date startTime);

    /**
     * 教练端 课程详情
     *  @param courseId 课程ID
     * @param mobile   教练手机  @return
     */
    CourseCoachDetailResultModel queryCoachCourseInfo(@Param("courseId") Integer courseId, @Param("mobile") String mobile);

    /**
     * 教练端 课程签到总计
     *
     * @param courseId     课程ID
     * @param courseNumber 课时序号
     * @param mobile       教练手机
     * @return 课程签到总计
     */
    int queryCoachCourseSignInCount(@Param("courseId") Integer courseId, @Param("courseNumber") int courseNumber, @Param("mobile") String mobile);

    /**
     * 根据实体查询签到
     *
     * @param courseSign
     * @return
     */
    CourseSign selectByCourseSign(CourseSign courseSign);

    /**
     * 统计私教费用明细
     * @param param
     * @return
     */
    List<CoursePrivteFeeVO> queryPrivateCoachFee(Map<String, Object> param);

    /**
     * 查询已销课数据
     *
     * @param orderId 订单 ID
     * @return 已销课数据列表
     */
    List<CourseSignDetailModel> selectSignDetailWithStoreNameByOrderId(@Param("orderId") int orderId);
    
    List<CourseSign> queryCourseSignByOrderId(Integer orderId);
    
    /**
     * 获取私教课程的开始和结束时间 
     * 私教课程： 取销课第一条 的开始时间 再取 销课最后一条的结束时间 拼接起来
     * @param orderId
     * @param userId
     * @return
     */
    String getPtCourseStartTimeAndEndTimeByOrderId(Integer orderId);

    /**
     *@Author: timo
     *@Date: 2018/3/25 20:45
     *@Description: 删除课程计划
     *
     *
     */
    Integer delCourseSginByCourseId(Integer courseId);

    /**
     *@Author: timo
     *@Date: 2018/3/27 11:28
     *@Description:
     * 查询排序最小的日程
     *
     */
    CourseSign queryMinSortCourseSignByCourseIdOrOrderId(@Param("courseId") Integer courseId, @Param("orderId")Integer orderId);

    /**
     *@Author: timo
     *@Date: 2018/3/28 14:13
     *@Description:
     * 更新私教日程计划
     *
     */
    int updatePrivateCourseSign(CourseSign courseSign);

    /**
     *@Author: timo
     *@Date: 2018/3/28 14:15
     *@Description:
     * 根据订单ID和开始结束时间查询该时间段内是否
     * 拥有课程计划
     *
     *  orderId 订单ID
     *  startTime 开始时间
     *  endTime 结束时间
     *  courseId 课程Id
     */
    int queryCourseScheduleCountBy(Map<String,Object> paramMap);


    /**
     *@Author: timo
     *@Date: 2018/3/29 18:52
     *@Description:
     * 查询是否还存在未添加的日程
     * 1 表示还有 0 表示没有
     */
    int queryHasNotAddedCourseSign(@Param("orderId") Integer orderId, @Param("courseId") Integer courseId);


    List<CourseSign> queryCoachNoteListPage(Page<CourseSign> page, Map<String,Object> paramMap);

    /**
     *@Author: timo
     *@Date: 2018/4/2 09:45
     *@Description:
     * 私教端 - 私教课程的授课记录
     *
     */
    List<OrderPrivateUser> queryCoachPrivateCourseSignList(Page<OrderPrivateUser> page,Map<String, Object> paramsMap);

    /**
     *@Author: timo
     *@Date: 2018/4/2 09:45
     *@Description:
     * 私教端 - 私教课程的授课记录 条数
     *
     */
    Integer queryCoachPrivateCourseSignCount(Map<String, Object> paramsMap);

    /**
     *@Author: timo
     *@Date: 2018/4/2 18:52
     *@Description:
     * 根据日程ID和用户ID查询订单
     *
     */

    List<UserCourseSignDetailModel> queryUserPrivateCourseSignDetailLog(@Param("userId") Integer userId, @Param("orderId") Integer orderId);


    /**
     *@Author: timo
     *@Date: 2018/4/3 11:03
     *@Description:
     * 查询私教课程在当天最大的日程
     *
     */
    CourseSign queryPtCourseCourseSignMaxToDayByOrderId(Integer orderId);


    OrderInfo queryOrderInfoBy(Map<String,Object> paramMap);

    /**
     *@Author: timo
     *@Date: 2018/4/4 12:19
     *@Description:
     * 判断是不是日程的最后一节课
     *
     */
    Integer checkIsLastClass(Integer courseId);

    List<UserCourseSignDetailModel> queryUserPlpeOrPlecCourseSignDetailLog(@Param("userId") Integer userId, @Param("orderId") Integer orderId);

    /**
     *@Author: timo
     *@Date: 2018/4/10 18:52
     *@Description:
     * 根据订单ID删除日程
     * 逻辑删除
     */
    int delCourseSignByOrderId(Integer orderId);

    /**
     *@Author: timo
     *@Date: 2018/4/10 18:54
     *@Description:
     * 根据日程ID删除该日程
     * 逻辑删除
     *
     */
    int delCourseSignByCourseSignId(Integer courseSignId);
}